package com.wazzapps.library.rootcheck;

import android.util.Log;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

public class RootChecker {
    private static boolean isRootDetected = false;

    private static boolean checkRootMethod1() {
        return false;
    }

    public static boolean isDeviceRooted() {
        boolean z = isRootDetected || checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
        isRootDetected = z;
        return z;
    }

    private static boolean checkRootMethod2() {
        String[] strArr = {"/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su", "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
        for (int i = 0; i < 10; i++) {
            String str = strArr[i];
            if (new File(str).exists()) {
                showMessage("Detected " + str);
                return true;
            }
        }
        showMessage("checkRootMethod2 pass");
        return false;
    }

    private static boolean checkRootMethod3() {
        Process process = null;
        try {
            Process exec = Runtime.getRuntime().exec(new String[]{"/system/xbin/which", "su"});
            if (new BufferedReader(new InputStreamReader(exec.getInputStream())).readLine() != null) {
                showMessage("Detected by which");
                if (exec != null) {
                    exec.destroy();
                }
                return true;
            }
            showMessage("checkRootMethod3 pass");
            if (exec != null) {
                exec.destroy();
            }
            return false;
        } catch (Throwable th) {
           th.printStackTrace();
        }
        return false;
    }

    private static void showMessage(String str) {
        Log.d("RootChecker", str);
    }
}